package com.ly.lypopupwindowdemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.ly.lypopupwindowdemo.R;
import com.ly.lypopupwindowdemo.adapter.MyAdapter1;
import com.ly.lypopupwindowdemo.views.CountView;
import com.ly.lypopupwindowdemo.views.MyListView;
import com.ly.lypopupwindowdemo.views.PasswordView;
import com.ly.lypopupwindowdemo.views.TitleView;

import java.util.ArrayList;
import java.util.List;

public class CountViewActivity extends AppCompatActivity implements PasswordView.PasswordListener,View.OnClickListener{

    private String tag = getClass().getSimpleName();
    private MyListView myListView;

    private MyAdapter1 adapter;

    private List<String> contentList = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_count_view);
        TitleView view2 = (TitleView) findViewById(R.id.title_view);
        CountView view1 = (CountView) findViewById(R.id.view1);
        MyListView view3 = (MyListView) findViewById(R.id.view3);

        PasswordView view4 = (PasswordView) findViewById(R.id.view4);
        view4.setPasswordListener(this);

        initList();

        int position = getIntent().getIntExtra("position",1);
        if (1==position){

            view1.setVisibility(View.VISIBLE);
            view2.setVisibility(View.GONE);
            view3.setVisibility(View.GONE);
            view4.setVisibility(View.GONE);
        }
        if (2==position){

            view1.setVisibility(View.GONE);
            view2.setVisibility(View.VISIBLE);
            view3.setVisibility(View.GONE);
            view4.setVisibility(View.GONE);

            view2.setTitleText("我是标题");
            view2.setLeftButtonText("返回");
        }
        if (3==position) {

            view1.setVisibility(View.GONE);
            view2.setVisibility(View.GONE);
            view3.setVisibility(View.VISIBLE);
            view4.setVisibility(View.GONE);

            myListView = (MyListView) findViewById(R.id.view3);
            myListView.setOnDeleteListener(new MyListView.OnDeleteListener() {
                @Override
                public void onDelete(int index) {
                    contentList.remove(index);
                    adapter.notifyDataSetChanged();
                }
            });

            adapter = new MyAdapter1(this, 0, contentList);
            myListView.setAdapter(adapter);
        }
        if (4==position){
            view1.setVisibility(View.GONE);
            view2.setVisibility(View.GONE);
            view3.setVisibility(View.GONE);
            view4.setVisibility(View.VISIBLE);

        }
    }

    private void initList() {
        contentList.add("Content Item 1");
        contentList.add("Content Item 2");
        contentList.add("Content Item 3");
        contentList.add("Content Item 4");
        contentList.add("Content Item 5");
        contentList.add("Content Item 6");
        contentList.add("Content Item 7");
        contentList.add("Content Item 8");
        contentList.add("Content Item 9");
        contentList.add("Content Item 10");
        contentList.add("Content Item 11");
        contentList.add("Content Item 12");
        contentList.add("Content Item 13");
        contentList.add("Content Item 14");
        contentList.add("Content Item 15");
        contentList.add("Content Item 16");
        contentList.add("Content Item 17");
        contentList.add("Content Item 18");
        contentList.add("Content Item 19");
        contentList.add("Content Item 20");

    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void passwordChange(String changeText) {
        Log.d(tag, "changeText = " + changeText);
    }

    @Override
    public void passwordComplete() {
        Log.d(tag, "passwordComplete");
    }

    @Override
    public void keyEnterPress(String password, boolean isComplete) {
        Log.d(tag, "password = " + password + " isComplete = " + isComplete);
    }
}
